package com.hzau.tourist_service_sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzau.tourist_service_sys.dao.ScenicSpot.ScenicSpotDao;
import com.hzau.tourist_service_sys.dao.ScenicSpot.TouristRouteDao;
import com.hzau.tourist_service_sys.pojo.ScenicSpot.ScenicSpot;
import com.hzau.tourist_service_sys.pojo.ScenicSpot.TouristRoute;
import com.hzau.tourist_service_sys.result.Result;
import com.hzau.tourist_service_sys.service.ScenicSpotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Service
public class ScenicSpotServiceImpl implements ScenicSpotService {
    @Autowired
    ScenicSpotDao scenicSpotDao;
    @Autowired
    TouristRouteDao touristRouteDao;
    private int pagesize=10;
    /*查询所有景点*/
    @Override
    public Result selectAlSpot(int pagenum, ScenicSpot scenicSpot) {
        System.out.println(scenicSpot);
        IPage page=new Page<>(pagenum,pagesize);
        LambdaQueryWrapper<ScenicSpot> lqw=new LambdaQueryWrapper<>();
        if (scenicSpot!=null)
        {lqw.like(scenicSpot.getSpotName()!=null,ScenicSpot::getSpotName,scenicSpot.getSpotName())
                .like(scenicSpot.getSpotLocation()!=null,ScenicSpot::getSpotLocation,scenicSpot.getSpotLocation())
                .in(scenicSpot.getTypes().size()!=0,ScenicSpot::getSpotType,scenicSpot.getTypes())
                .le(scenicSpot.getSpotPrice()!=-1.0,ScenicSpot::getSpotPrice,scenicSpot.getSpotPrice());


        }
       scenicSpotDao.selectPage(page, lqw);
        System.out.println(page.getRecords());
        return Result.success(page.getRecords());
    }
    /*查询景点详情*/
    @Override
    public Result selectSpotDetail(long spotId) {
        return Result.success(scenicSpotDao.selectById(spotId));
    }
    /*查询路线*/
    @Override
    public Result selectWayAll(int pagenum, TouristRoute touristRoute) {
        IPage page=new Page(pagenum,pagesize);
        LambdaQueryWrapper<TouristRoute> lqw=new LambdaQueryWrapper<>();
        if(touristRoute!=null){
            lqw.ge(touristRoute.getRouteLength()!=-1,TouristRoute::getRouteLength,touristRoute.getRouteLength())
            .le(touristRoute.getMaxRouteLength()!=-1,TouristRoute::getRouteLength,touristRoute.getMaxRouteLength())
                    .ge(touristRoute.getTimeSpent()!=-1,TouristRoute::getTimeSpent,touristRoute.getTimeSpent())
                    .ge(TouristRoute::getRecommendLevel,touristRoute.getRecommendLevel())
                    .le(touristRoute.getMaxTimeSpent()!=-1,TouristRoute::getTimeSpent,touristRoute.getMaxTimeSpent());
        }
        touristRouteDao.selectPage(page, lqw);
        return Result.success(page.getRecords());
    }

    @Override
    public Result selectWayDetail(long routeId) {

        return Result.success(touristRouteDao.selectById(routeId));
    }

}
